package com.loong.testretrofitrxjavamvp.view;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.le.base.BaseActivity;
import com.loong.testretrofitrxjavamvp.R;
import com.loong.testretrofitrxjavamvp.inf.view.IMainView;
import com.loong.testretrofitrxjavamvp.presenter.MainPresenter;

/**
*  @describe  -- 用户交互view
*  @author zgq
*  @version 1.0.0
*  @date 2018/11/13
*/
public class MainActivity extends BaseActivity<MainPresenter> implements IMainView {

    private TextView tvDis;
    private EditText etContent;
    private Button btnFy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tvDis = findViewById(R.id.tv_dis);
        etContent = findViewById(R.id.et_content);
        btnFy = findViewById(R.id.btn_fl);

        onClickBtn();
    }

    private void onClickBtn() {
        btnFy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startFy();
            }
        });
    }

    private void startFy() {
        String content = etContent.getText().toString().trim();
        if (TextUtils.isEmpty(content)){
            showToast("请输入要翻译的内容");
            return;
        }
        showProgress("努力翻译中...", false);
        presenter.netData(content);
    }


    /**
     * 持有presenter对象
     * @return
     */
    @Override
    protected MainPresenter getPresenter() {
        return new MainPresenter();
    }


    @Override
    public void getDisplayData(String content) {
        tvDis.setText(content);
    }

    @Override
    public void showError(int flag, Throwable e) {
        dismissProgress();
        showToast("服务器不给力，请重试");
    }

    @Override
    public void complete(int flag) {
        dismissProgress();
    }


}
